package com.seeyon.apps.kk.manager;

import java.sql.Clob;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CaseSaveManagerImpl extends BaseManager {
	private static final Log log = LogFactory.getLog(CaseSaveManagerImpl.class);

	public boolean saveCase(Map<String, Object> map) {
		List<Map<String, Object>> sortL = this.ibatisQueryDao.queryForList("kkcase_select_lockkk", map);
		try {
			if (sortL.isEmpty()) {
				this.ibatisQueryDao.getSqlMapClientTemplate().insert("kkcase_insert_lockkk", map);
			} else {
				this.ibatisQueryDao.getSqlMapClientTemplate().update("kkcase_update_lockkk", map);
			}
			return true;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error("起案保存失败");
		}
		return false;
	}

	public String getCaseContext(Map<String, Object> map) {
		List<Map<String, Object>> sortL = this.ibatisQueryDao.queryForList("kkcase_select_lockkk", map);
		if (sortL.isEmpty())
			return "";
		Map<String, Object> sortM = sortL.get(0);
		Clob clob = (Clob) sortM.get("text");// java.sql.Clob
		String detailinfo = "";
		if (clob != null) {
			try {
				detailinfo = clob.getSubString((long) 1, (int) clob.length());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return detailinfo;
	}

	public String getCaseContextTow(Map<String, Object> map) {
		List<Map<String, Object>> sortL = this.ibatisQueryDao.queryForList("kkcase_select_lockkk", map);
		if (sortL.isEmpty())
			return "";
		Map<String, Object> sortM = sortL.get(0);
		Clob clob = (Clob) sortM.get("text");// java.sql.Clob
		String detailinfo = "";
		if (clob != null) {
			try {
				detailinfo = clob.getSubString((long) 1, (int) clob.length());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return detailinfo.replaceAll("\"", "\'");
	}
}
